<template>
  <swiper class="swiper" :options="swiperOption">
    <swiper-slide v-for="(page,index) in pages" :key="index">
      <div class="icons" >
        <div class="icon" v-for="icon in page" :key="icon.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="icon.imgurl">
          </div>
          <div class="icon-text">{{icon.keywords}}</div>
        </div>
      </div>
    </swiper-slide>
    <div class="swiper-pagination"  slot="pagination"></div>
  </swiper>
</template>

<script>
  export default {
    name: 'HomeIcons',
    data: function () {
      return {
        swiperOption: {
          pagination: '.swiper-pagination'
        },
        iconsList: [
          {
            id: '0001',
            imgurl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
            keywords: '景点门票'
          },
          {
            id: '0002',
            imgurl: 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
            keywords: '一日游'
          },
          {
            id: '0003',
            imgurl: 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
            keywords: '本地玩乐'
          },
          {
            id: '0004',
            imgurl: 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
            keywords: '动物植园'
          },
          {
            id: '0005',
            imgurl: 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
            keywords: '比游榜单'
          },
          {
            id: '0006',
            imgurl: 'http://img1.qunarzz.com/piao/fusion/1803/bd/9f7b9b2b60c1502.png',
            keywords: '自然风光'
          },
          {
            id: '0007',
            imgurl: 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
            keywords: '海滨海岛'
          },
          {
            id: '0008',
            imgurl: 'http://img1.qunarzz.com/piao/fusion/1803/bd/9f7b9b2b60c1502.png',
            keywords: '踏青赏花'
          },
          {
            id: '0009',
            imgurl: 'http://img1.qunarzz.com/piao/fusion/1803/bd/9f7b9b2b60c1502.png',
            keywords: '城市观光'
          },
          {
            id: '00010',
            imgurl: 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
            keywords: '全部玩乐'
          }
        ]
      }
    },
    computed: {
      pages: function () {
        const pages = []
        this.iconsList.forEach((item, index) => {
          const page = Math.floor(index / 8)
          if (!pages[page]) {
            pages[page] = []
          }
//          var ss = 'pages[page] ='
//          console.log(ss + pages[page])
          pages[page].push(item)
        })
        return pages
      }
    }
  }
</script>

<style lang="stylus" scoped>
  .swiper >>> .swiper-pagination-bullet-active
    background : white
  .icons
    margin-top : 10px
    width: 100%
    height: 0
    padding-bottom: 50%
    .icon
      position: relative
      overflow: hidden
      float: left
      width: 25%
      height: 0
      padding-bottom: 25%
      .icon-img
        position: absolute
        top: 0
        left: 0
        right: 0
        bottom: .44rem
        .icon-img-content
          height: 100%
          display: block
          margin 0 auto
      .icon-text
        position: absolute
        left: 0
        right: 0
        bottom: 0
        height: .44rem
        line-height: .44rem
        text-align: center
        color: black

</style>
